<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		 <meta name="viewport" content="width=device-width,initial-scale=1.0">
		<title>新增发票抬头</title>
		<link href="css/index.css" rel="stylesheet" />
	</head>
	<body>
	<div class="wrapInputInfo">
		<div class="headTitle">
		<img onclick="goback()" src="./img/leftArrow.jpg" />
		<p>开具电子发票</p>
       	</div>
		<div class="spaceHead" style="display: none;">
			<img class="addImg" src="./img/add.jpg" />
			<span>添加发票抬头</span>
			<img class="headrightImg" src="./img/rightArrow.jpg" />
		</div>
		<div class="ticketHead" style="display: none;">
			<span class="spanTitle">发票抬头</span>
			<div class="divContentHead">
				<p class="headContent">
					<span class="spanName">武汉天喻信息产业股份有限公司售后服务</span>
					<span class="spanNum">税号:</span>
				</p>
				<img class="rightArrow" src="./img/rightArrow.jpg" />
			</div>
			<p class="pMail"><span class="spanMailName">电子邮箱</span><span class="spanMailContent">llsda@aaa.com.cn</span><img src="./img/rightArrow.jpg" /></p>
		</div>
		<div class="divContent">
			<p class="pType"><span class="spanType">发票类型</span><span class="spanName">交通一卡通</span></p>
			<p class="pMoney"><span class="spanMoney">发票金额</span><span class="spanMoneyNum">0.00元</span></p>
		</div>
		<p class="mark"><span>备注说明</span><input maxlength="100" placeholder="备注说明,非必填" /></p>
		<button class="sureInputInfo">确定</button>
		<p class="pText">请确认邮箱无误，电子发票将在系统开具后发送至您的邮箱，请注意查收</p>
		
		<div class="wrapResend" style="position: absolute;left: 0;top: 0;display: none;z-index: 100;width: 100%;height: 100%;">
		<p>
			<span>电子邮箱</span>
			<input class="inputMail" placeholder="请输入电子邮箱" />
		</p>
		<button class="submit">确定</button>
	</div>
	
	<!--选择抬头-->
	<div class="wrapTicketinfo" style="overflow-y: scroll;padding-bottom: 1.8rem;box-sizing: border-box;position: absolute;left: 0;top: 0;widows: 100%;z-index: 100;display: none;height: 100%;">
		<ul>
			<li>
				<p>武汉天喻信息产业有限公司</p>
				<span>税号：</span>
				<small>企业</small>
			</li>
			<li>
				<p>武汉天喻信息产业有限公司</p>
				<small>个人</small>
			</li>
		</ul>
		<div style="position: fixed;bottom: 0rem;left: 0;background: white;width: 100%;height: 1.8rem;">
			<button class="sure" style="position: absolute;left: 4%;top: 0.2rem;margin-top: 0;">+ 新增报销凭证报销抬头</button>
		</div>
	</div>
		
	</div>
</body>
<html>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/oldPublic.js" ></script>
	<script src="js/code.js"></script>
	<script src="js/security.js"></script>
<script>
	var login_name = sessionStorage.getItem('login_name');
	var telphone = sessionStorage.getItem('telphone');
	var orgcode = sessionStorage.getItem('orgcode');
	var arrList = window.location.href.split('?')[1].split('&')[0].split('=')[1];
	var allPrice = window.location.href.split('?')[1].split('&')[1].split('=')[1];
	$('.spanMoneyNum').html(allPrice+'元');
	var inputMail = sessionStorage.getItem('inputMail')||'';
	var isPersonType=['1'];
	var title_id=[];
	arrList = decodeURI(arrList);
		$.ajax({
			type:"post",
			url:sessionStorage.getItem('ipconfig'),
			data:JSON.stringify({data:encryptByDESModeEBC(JSON.stringify({"tag": "9102", 'login_name': login_name, 'telphone': telphone, 'bus_type': '1','orgcode':orgcode }))}),
			contentType: "application/json;charset=utf-8",
			success:function(data){
				console.log(data);
				if(data.result=='00'){
					var title_info = JSON.parse(data.title_info);
					console.log(title_info);
					if(title_info.length==0){
					$('.spaceHead').show();
					}else{
						$('.headContent .spanName').html(title_info[0].name);
						isPersonType[0] = title_info[0].title_type;
						title_id[0] =  title_info[0].title_id;
						if(!title_info[0].taxpayer_num){
							$('.headContent .spanNum').html('');
						}else{
							$('.headContent .spanNum').html('税号:'+(title_info[0].taxpayer_num||''));
						}
					$('.spanMailContent').html(title_info[0].email);
					$('.ticketHead').show();	
					}
				}else{
					showWarn(data.description);
				}
			}
		});
		
		$('.pMail').click(function(){ //修改邮箱
			$('.inputMail').val($('.spanMailContent').html());
			$('.wrapResend').show();
		})
		var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
		$('.submit').click(function(){
			var inputMail = $('.inputMail').val();
			if(!reg.test(inputMail)){
				showWarn('请输入正确的邮箱地址！');
			}else{
				$('.spanMailContent').html(inputMail);
				$('.wrapResend').hide();
			}
		})

	$(' .sureInputInfo').click(function(){
		var inputMail = $('.spanMailContent').html();
		var mask = $('.mark input').val();
		var title_idArr = JSON.stringify(title_id[0]);
		$('.sureInputInfo').html('提交中...');
		$('.sureInputInfo').attr('disabled','disabled');
		console.log(arrList);
		$.ajax({
				type:"post",
				url:sessionStorage.getItem('ipconfig'),
				data:JSON.stringify({data:encryptByDESModeEBC(JSON.stringify({"tag": "9104",'login_name': login_name, 'telphone': telphone, 'status': '0','txn_list':arrList,'email':inputMail,'remark':mask,'title_no':title_idArr,'orgcode':orgcode}))}),
				success:function(data){
					console.log(data);
					if(data.result=='00'){
						window.location.href = './kaiSuccess.html';
					}else{
						showWarn(data.description);
						$('.sureInputInfo').html('提交失败 请重试');
						$('.sureInputInfo').attr('disabled','');
					}
				}
		});
	})
	$('.spaceHead').click(function(){
			window.location.href = './addHead.html';
	})
	
	//选择抬头
	$('.divContentHead').click(function(){
		$('.wrapTicketinfo').show();
	})
	$('.wrapTicketinfo .sure').click(function(){
		window.location.href = './addHead.html';
	})
			$.ajax({
				type:"post",
				url:sessionStorage.getItem('ipconfig'),
				data:JSON.stringify({data:encryptByDESModeEBC(JSON.stringify({"tag": "9102", 'login_name': login_name, 'telphone': telphone, 'bus_type': '1','orgcode':orgcode }))}),
				success:function(data){
					console.log(data);
					if(data.result=='00'){
						var title_info = JSON.parse(data.title_info);
						var str = '';
						for(var i=0;i<title_info.length;i++){
							var isperson = '';
							var sbh = '';
						
							if(title_info[i].title_type=='0'){
								isperson = '个人';
							}else{
								isperson = '公司';
								sbh = '<span>税号：'+title_info[i].taxpayer_num+'</span>'
							}
							str+='<li onclick = "gotoedit('+title_info[i].title_id+','+title_info[i].title_type+')">'+
									'<p>'+title_info[i].name+'</p>'+sbh+
									'<small>'+isperson+'</small>'+
								'</li>'
						}
						$('ul').html(str);
					}
				}
			}); 
			function gotoedit(a,b){
				  //个人b=1
			isPersonType[0] = a;
		    console.log(a);
		    isPersonType = a;
			$.ajax({
			type:"post",
			url:sessionStorage.getItem('ipconfig'),
			data:JSON.stringify({data:encryptByDESModeEBC(JSON.stringify({"tag": "9102", 'login_name': login_name, 'telphone': telphone, 'bus_type': '1','orgcode':orgcode }))}),
			success:function(data){
				console.log(data);
				if(data.result=='00'){
					var title_info = JSON.parse(data.title_info);
					for(var i=0;i<title_info.length;i++){
						if(title_info[i].title_id==a){
							$('.headContent .spanName').html(title_info[i].name);
							title_id[0] =  title_info[i].title_id;
								if(!title_info[i].taxpayer_num){
								$('.headContent .spanNum').html('');
								}else{
								$('.headContent .spanNum').html('税号:'+(title_info[i].taxpayer_num||''));
								}
							$('.spanMailContent').html(title_info[i].email);
							
							$('.wrapTicketinfo').hide();
						}
					}
				}else{
					showWarn(data.description);
				}
			}
		});
			}
	
</script>

